import router from "@/utils/helpers/hRouter"
import store from '@/store'
import utils from '@/utils/lodash'
import storage from "@/utils/helpers/storage"


//路由守卫
router.beforeEach = async (navType, to) => {
	function next() {
		//进行route的转换
		return uni[navType]({
			url: utils.initUrl(to)
		})
	}
	
	// #ifdef MP-WEIXIN
	next()
	// #endif
	// #ifdef H5
	let {
		token
	} = store.getters
	if (to.path == '/pages/login/login') {
		next()
	}
	else{
		if (!token) {
			router.push({
				path: "/pages/login/login",
				params: {
					redirect: to.path
				}
			})
		}else {
			next()
		}
	}
	// #endif
}
